<?php
namespace Smanage\Controller;
use Common\Controller\AdminbaseController;

class StypeadminController extends AdminbaseController{
		function _initialize() {
			parent::_initialize();
							
		}
		function index(){
			$sbtype_model = D('Sbtype');
			$count = $sbtype_model->count();
			$Page  = $this->Page($count,10);  // 实例化分页类 传入总记录数和每页显示的记录数(15)
			$show  = $Page->show("Admin");   // 分页显示输出
			$type_lists  = $sbtype_model->order('type_id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
			$this->assign('type_lists',$type_lists);  // 赋值数据集
			$this->assign('Page',$show);   // 赋值分页输出	
			$this -> display();
		}
		function add(){		
			$this->display();		
		}
		function add_post(){
				$stype_model = D('Sbtype');
				if(IS_POST){
					if($stype_model->create()){
						$result = $stype_model->add();
						if($result!==false){
							$this->success("添加成功！",U('Stypeadmin/index'));
						}else{
							$this->error("添加失败！");
						}
						
					}
				}
			}
		
		function edit(){			
			$id = intval(I("get.id"));
			//dump($id);
			$typeinfo = D("Sbtype")->where(array("type_id"=>$id))->find();
			//dump($sbinfo);
			$this -> assign('typeinfo',$typeinfo);						
			$this -> display();
			//dump($_POST);
			
		}
		
		function edit_post(){
			$id = intval(I("post.id"));
			//dump($id);
			$result = D("Sbtype")->where(array("type_id"=>$id))->save($_POST);
			//dump($result);
			if($result!==false){
				$this->success("修改成功！",U('Stypeadmin/index'));
			}else{
				$this->error("修改失败！");
			}
		}
		
		function delete(){
			$id = intval(I('get.id'));
			$result = D("Sbtype")->where(array("type_id"=>$id))->delete();
			if($result!==false){
				$this->success("删除成功！", U("Stypeadmin/index"));
				}else{
				$this->error('删除失败！');
			}
			
		}	
	
}